package de.fhb.itunes.repository.DataAccess;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import de.fhb.itunes.repository.data.Film_VO;
import de.fhb.itunes.repository.data.MedienFile_VO;
import de.fhb.itunes.repository.data.Playlist_VO;
import de.fhb.itunes.repository.jdbc.DataAccessException;
import de.fhb.itunes.repository.jdbc.JdbcDAOBase;

public class DAO_Playlist extends JdbcDAOBase implements IDAO_Playlist{

	
	@Override
	public Playlist_VO getbyUserID(int id) {
		Playlist_VO vo;
		Connection con = null;
		PreparedStatement ps = null;
		ResultSet rs = null;

		String sqlStr = "SELECT ID FROM  [itunes].[dbo].[PlaylistSatz] WHERE UserID = ?";

		try {
			con = getConnection();
			ps = con.prepareStatement(sqlStr);
			ps.setInt(1, id);
			rs = ps.executeQuery();
			vo =  transformToPl(rs);
		} catch (SQLException sqle) {
			throw new DataAccessException("Error executing " + sqlStr, sqle);
		} finally {
			try {
				// close the resources
				if (ps != null)
					ps.close();
				if (con != null)
					con.close();
			} catch (SQLException sqlee) {
				throw new DataAccessException("Can't close connection", sqlee);
			}
		}
		return vo;
	}
	private Playlist_VO transformToPl(ResultSet rs) throws SQLException{
		List<Integer> idList = new LinkedList();
		Playlist_VO vo;
		while (rs.next()) {
			idList.add(rs.getInt("TitelID"));
		}
		vo = map2VO(idList);
		return vo;
	}
	@Override
	protected Object map2VO(ResultSet rs) throws SQLException {
		return null;
	}
	private Playlist_VO map2VO(List<Integer> listOfTitelIDs) throws SQLException {
		Playlist_VO playlist = new Playlist_VO();
		
		return null;
	}

}
